package cn.wjdiankong.levideo.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import cn.wjdiankong.levideo.R;
import cn.wjdiankong.levideo.view.ProgressWheel;

public class WebViewActivity extends BaseActivity{
	
	private WebView webView;
	private ProgressWheel progress;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_webview);
		init();
	}
	
	private void init(){
		initView();
		initData();
	}
	
	@SuppressLint("SetJavaScriptEnabled") 
	public void initData(){
		super.initData();
		setTitle("安全不息,逆向不止");
		setLeftImg(R.drawable.back_icon);
		Intent intent = getIntent();
		String infoUrl = intent.getStringExtra("_infoUrl");
		webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.getSettings().setUserAgentString("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
		webView.setWebViewClient(new WebViewClient()  {  
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
            @Override  
            public void onPageFinished(WebView view,String url)  {  
            	webView.setVisibility(View.VISIBLE);
            	progress.setVisibility(View.GONE);
            }  
        });  
		webView.loadUrl(infoUrl);
	}
	
	@Override
	protected void initView(){
		super.initView();
		webView = (WebView)findViewById(R.id.webview);
		progress = (ProgressWheel)findViewById(R.id.progress);
		webView.setVisibility(View.GONE);
		progress.setVisibility(View.VISIBLE);
	}
	
	public static void startDefault(Context context, String url){
		Intent intent = new Intent(context,WebViewActivity.class);
		intent.putExtra("_infoUrl", url);
		context.startActivity(intent);
	}
	
	@Override
	protected void clickLeftImg() {
		super.clickLeftImg();
		finish();
	}
	
	@Override
	protected String getPageName() {
		return "webview";
	}

}
